home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / CALib & You… / Source / CALib / Implementation / ProxyPart / CAProxyPart.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  38.0 KB  |  1,522 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CAProxyPart.cpp
  3.  
  4.     Contains:    CAProxyPart CALib proxy part editor class implementation.
  5.                 Built using PartMaker , then modified.
  6.  
  7.     Written by:    Rick Badertscher, Tantek Çelik, Eric Soldan, Jens Alfke,
  8.                 AND PartMaker AND Steve Foley
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>    11/18/95    RB        Major strip down, Removed many obsolete methods
  13.          <2>    11/10/95    RB        Modified to keep storage unit refs to frames in
  14.                                      kCAPropEmbeddedFrames instead of in kODPropContents
  15.          <1>     6/15-6/30    RB        Major rewrite.  
  16.  
  17.         ------------------------------------------------------------------------------
  18.          <36>     5/16/95    SJF        Fix handle mouse down in border (HandleEvent)
  19.                                      to change an activated frame to selected on a drag
  20.          <32>     5/16/95    SJF        Condense Frame negotiation callbacks into
  21.                                      common subroutines in UTIL...
  22.          <30>     5/15/95    RB        Removing default "Container" behavior.
  23.                                      Fixing up some exception handling code.
  24.                                      
  25.          <29>     5/12/95    RB        Integrating new selection implementation.
  26.            <28>     5/09/95    SJF        Fixes to drag outline calculation
  27.            <22>     5/06/95    SJF        Drag & Drop support changes
  28.            <21>     5/05/95    DAS        fixed 1 declaration for MWC v6.0 scope rule change
  29.                                        some minor cleanup
  30.            <20>     4/23/95    RB        Adding support for CA Focus transfer handlers
  31.            <19>     4/23/95    SJF        Splitting UTIL methods into CAProxyPartUTIL.cpp
  32.            <18>     4/23/95    RB        Fixing menu stuff
  33.            <17>     4/22/95    RB        Uncommented ProxyExtension allocation.
  34.            <16>     4/19/95    RB        A couple b1c18 mods.  Commented out all
  35.                                        enables in AdjustPartMenus except insert.
  36.        <15+>     4/19/95    SJF        Fix bug in AdjustPartMenus
  37.          <15>     4/08/95    RB        Major makeover.  Fixed mouse event handling,
  38.                                     Updated with new TFrameProxy class.  
  39.         <14>      4/7/95    SJF        Change _CAProxyPart_ROOT_ to
  40.                                     _ALLOCATE_STORAGE_
  41.          <13>     4/05/95    RB        More Fixes for b1c14.  Temp commenting out exception
  42.                                      handling code.
  43.          <13>     4/04/95    RB        Fixes for b1c14.  Store all part values in
  44.                                      the root SU (used to create an additional SU)
  45.          <12>     4/02/95    RB        Integrating changes for b1c14 build
  46.          <11>     4/01/95    RB        Adding support for CAWindowActivateHandler()
  47.          <10>     3/31/95    RB        Adding support for multiple root frames
  48.          <9>     3/30/95    RB        Mods to correctly handle first click behavior.
  49.                                      Added method UTIL_HandleActivateEvent()
  50.          <8>     3/15/95    SJF        Merge in RickB's changes
  51.          <7>     3/15/95    SJF        Split Drag & Drop support methods out into
  52.                                     another file (CAProxyPartDnD.cpp)
  53.          <6>     2/28/95    SJF        Inhibit drawing of the ProxyPart rectangle
  54.                                     in ::Draw
  55.          <4+>     2/28/95    SJF        Turn off rectangle drawing in ::Draw method, add
  56.                                      constant for ScrollBarOffset for rectangle calculations
  57.          <4>     2/21/95    SJF        fix include paths, incorporate RickB's changes
  58.          <3>     2/13/95    SJF        Interim checkin to update project database
  59.          <0>    11/16/94    SJF        first written
  60.          
  61.     To Do:
  62. */
  63.  
  64. #ifndef _ALTPOINT_
  65. #include <AltPoint.h>
  66. #endif
  67.  
  68. #ifndef _EXCEPT_
  69. #include <Except.h>
  70. #endif
  71.  
  72. #ifndef SOM_ODFrame_xh
  73. #include <Frame.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODFacet_xh
  77. #include <Facet.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODShape_xh
  81. #include <Shape.xh>
  82. #endif
  83.  
  84. #ifndef SOM_ODFacetIterator_xh
  85. #include <FacetItr.xh>
  86. #endif
  87.  
  88. #ifndef SOM_ODStorageSystem_xh
  89. #include <ODStor.xh>
  90. #endif
  91.  
  92. #ifndef _ITEXT_    
  93. #include <IText.h>
  94. #endif
  95.  
  96. #ifndef SOM_ODDraft_xh
  97. #include <Draft.xh>
  98. #endif
  99.  
  100. #ifndef SOM_ODArbitrator_xh
  101. #include <Arbitrat.xh>
  102. #endif
  103.  
  104. #ifndef SOM_ODCanvas_xh
  105. #include <Canvas.xh>
  106. #endif
  107.  
  108. #ifndef SOM_ODFrameFacetIterator_xh
  109. #include <FrFaItr.xh>
  110. #endif
  111.  
  112. #ifndef SOM_ODFoci_xh
  113. #include <Foci.xh>
  114. #endif
  115.  
  116. #ifndef SOM_Module_OpenDoc_StdProps_defined    //•
  117. #include <StdProps.xh>
  118. #endif
  119.  
  120. #ifndef SOM_Module_OpenDoc_StdTypes_defined    //•
  121. #include <StdTypes.xh>
  122. #endif
  123.  
  124. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  125. #include <StdDefs.xh>
  126. #endif
  127.  
  128. #ifndef SOM_Module_OpenDoc_Commands_defined
  129. #include <CmdDefs.xh>
  130. #endif
  131.  
  132. #ifndef SOM_ODStorageUnit_xh
  133. #include <StorageU.xh>
  134. #endif
  135.  
  136. #ifndef SOM_ODStorageUnitCursor_xh
  137. #include <SUCursor.xh>
  138. #endif
  139.  
  140. #ifndef SOM_ODTransform_xh
  141. #include <Trnsform.xh>
  142. #endif
  143.  
  144. #ifndef SOM_ODFocusSet_xh
  145. #include <FocusSet.xh>
  146. #endif
  147.  
  148. #ifndef SOM_ODMenuBar_xh
  149. #include <MenuBar.xh>
  150. #endif
  151.  
  152. #ifndef SOM_ODWindow_xh
  153. #include <Window.xh>
  154. #endif
  155.  
  156. #ifndef SOM_ODWindowState_xh
  157. #include <WinStat.xh>
  158. #endif
  159.  
  160. #ifndef _ODUTILS_
  161. #include <ODUtils.h>
  162. #endif
  163.  
  164. #ifndef _STDTYPIO_
  165. #include <StdTypIO.h>
  166. #endif
  167.  
  168. #ifndef SOM_ODStorageUnitRefIterator_xh
  169. #include <SURefItr.xh>
  170. #endif
  171.  
  172. #ifndef _ISOSTR_
  173. #include <ISOStr.h>
  174. #endif
  175.  
  176. #ifndef SOM_CAProxyEmbeddedFramesIterator_xh
  177. #include "CAProxyEmFrI.xh"
  178. #endif
  179.  
  180. #ifndef _CAPROXYPARTDEF_
  181. #include "CAProxyPartDef.h"
  182. #endif
  183.  
  184. #ifndef _CAPROXYPART_
  185. #include "CAProxyPart.h"
  186. #endif
  187.  
  188. #ifndef SOM_CAProxyExtension_xh
  189. #include "CAProxyExtension.xh"
  190. #endif
  191.  
  192. #ifndef _FOCUSLIB_
  193. #include <FocusLib.h>
  194. #endif
  195.  
  196. #ifndef _ORDCOLL_
  197. #include <OrdColl.h>
  198. #endif
  199.  
  200. #ifndef _STORUTIL_
  201. #include <StorUtil.h>
  202. #endif
  203.  
  204. #ifndef _TEMPOBJL_
  205. #include <TempObj.h>
  206. #endif
  207.  
  208. #ifndef _CAPROXYDEBUG_
  209. #include "CAProxyDebug.h"
  210. #endif
  211.  
  212. //====================================================================
  213. // Miscellaneous
  214. //====================================================================
  215.  
  216. //==============================================================================
  217. // Part Library Globals (shared across instances of the part)
  218. //==============================================================================
  219.  
  220. #pragma segment CAProxyPart
  221.  
  222.  
  223. static    ODUShort        gGlobalsUsageCount    = 0;
  224.  
  225. static    ODMenuBar*        gMenuBar            = kODNULL;
  226. static    ODFocusSet*        gUIFocusSet            = kODNULL;    
  227.             
  228. static    ODTypeToken        gSelectionFocus        = 0;
  229. static    ODTypeToken        gMenuFocus            = 0;
  230. static    ODTypeToken        gModalFocus            = 0;
  231. static    ODTypeToken        gKeyFocus            = 0;
  232. static    ODTypeToken        gClipboardFocus        = 0;
  233.         
  234. //====================================================================
  235. // Constants
  236. //====================================================================
  237.  
  238.  
  239. //====================================================================
  240. // CAProxyPart
  241. //====================================================================
  242.  
  243.  
  244.         
  245. CFrameInfo::CFrameInfo (Environment* ev, ODID frameID, ODDraft* draft)
  246. {
  247.     fFrameID = frameID;
  248.     fDraft = draft;
  249.     fFrame = kODNULL;
  250.     fEv = ev;
  251. }
  252.  
  253. CFrameInfo::~CFrameInfo ()
  254. {
  255.     ODReleaseObject (fEv, fFrame);
  256. }
  257.  
  258. void CFrameInfo::Internalize(void)
  259. {
  260.     if (fFrame == kODNULL)
  261.         fFrame = fDraft->AcquireFrame (fEv, fFrameID);
  262.         
  263. }
  264.  
  265. void CFrameInfo::Externalize(ODStorageUnit* su)
  266. {
  267.     ODStorageUnitRef    value;
  268.     ODSize                streamSize;
  269.  
  270.     ODSUExistsThenFocus (fEv, su, kCAPropEmbeddedFrames, kODStrongStorageUnitRefs);
  271.  
  272.     streamSize = su->GetSize(fEv);
  273.     su->SetOffset (fEv, streamSize);
  274.     
  275.     su->GetStrongStorageUnitRef(fEv, fFrameID, value);
  276.     StorageUnitSetValue(su, fEv, kODStorageUnitRefLen, value);
  277. }
  278.  
  279. ODFrame* CFrameInfo::GetFrame(void)
  280. {
  281.     if (fFrame == kODNULL)
  282.     {
  283.         fFrame = fDraft->AcquireFrame (fEv, fFrameID);
  284.     }
  285.     
  286.     return (fFrame);
  287. }
  288.  
  289. void CFrameInfo::Close(void)
  290. {
  291.     fFrame->Close(fEv);
  292.     fFrame = kODNULL;
  293. }
  294.  
  295. void CFrameInfo::Remove(void)
  296. {
  297.     fFrame->Remove(fEv);
  298.     fFrame = kODNULL;
  299. }
  300.  
  301. ODID CFrameInfo::GetID(void)
  302. {
  303.     return fFrameID;
  304. }
  305.  
  306. CDisplayFrameInfo::CDisplayFrameInfo (Environment* ev, ODFrame* frame)
  307. {
  308.     fFrameID = frame->GetID(ev);
  309.     fFrame = frame;
  310.     fEv = ev;
  311.     frame->Acquire(ev);
  312. }
  313.  
  314. CDisplayFrameInfo::~CDisplayFrameInfo ()
  315. {
  316.     ODReleaseObject (fEv, fFrame);
  317. }
  318.  
  319. //--------------------------------------------------------------------
  320. // CAProxyPart::CAProxyPart
  321. //--------------------------------------------------------------------
  322.  
  323. CAProxyPart::CAProxyPart( void )
  324. {
  325. #if TRACING
  326.     InitTracing(NULL, false);
  327. #endif
  328.  
  329.     fDirty                        = kODFalse;
  330.     fCADocumentRef                = kODNULL;
  331.     fActiveFrame                = kODNULL;
  332.     fSelf                        = kODNULL;
  333.     fDisplayFrame                = kODNULL;
  334.     fEmbeddedFrames                = kODNULL;
  335.     fActiveBorderShape            = kODNULL;
  336.     
  337.     fProxyExt                    = kODNULL;
  338.  
  339.     fCADnDTrackHnd                = kODNULL;
  340.     fTrackRefCon                = kODNULL;
  341.     fCADnDReceiveHnd            = kODNULL;
  342.     fReceiveRefCon                = kODNULL;
  343.  
  344.     fCAWindowActivateHandler    = kODNULL;
  345.     fCAFocusAquiredHandler        = kODNULL;
  346.     fCAFocusLostHandler            = kODNULL;
  347.     fCAAdjustBorderHandler        = kODNULL;
  348.     fCAAdjustBorderHook            = kODNULL;
  349.     fCAFrameShapeRequestHandler    = kODNULL;
  350.     fCAFrameShapeRequestHook    = kODNULL;
  351.  
  352. }
  353.  
  354.  
  355. //--------------------------------------------------------------------
  356. // CAProxyPart::~CAProxyPart
  357. //--------------------------------------------------------------------
  358.  
  359. CAProxyPart::~CAProxyPart( void )
  360. {
  361.     ODDeleteObject (fProxyExt);
  362.  
  363. }
  364.  
  365. //-------------------------------------------------------------------------
  366. // CAProxyPart::AbortRelinquishFocus
  367. //-------------------------------------------------------------------------
  368.  
  369. void CAProxyPart::AbortRelinquishFocus(Environment* ev, ODTypeToken focus, ODFrame* ownerFrame,
  370.                                                         ODFrame* proposedFrame)
  371. {
  372. ODUnused(ev);
  373. ODUnused(focus);
  374. ODUnused(ownerFrame);
  375. ODUnused(proposedFrame);
  376.     // •• 6/23/94
  377.     // Being here means that BeginRelinquishFocus said no to one of the foci.
  378.     // You are being informed of this because you may have already taken action
  379.     // based on a previous focus.  Note that if foci are managed as a set, if
  380.     // BeginRelinquishFocus says false to any of the foci, then no action is
  381.     // taken.  If however the foci are tested one at a time, it is possible that
  382.     // the part has already taken action based on the first foci, and therefore
  383.     // needs to undo something once a foci says no thanks.
  384. }
  385.  
  386.  
  387. //--------------------------------------------------------------------
  388. // CAProxyPart::AdjustBorderShape
  389. //--------------------------------------------------------------------
  390.  
  391. ODShape* CAProxyPart::AdjustBorderShape(Environment* ev, ODFacet* embeddedFacet, ODShape* shape)
  392.  
  393. // Adjusts the shape of the active frame border of an embedded
  394. // frame.
  395. //
  396. // Called by the arbitrator object.
  397. //
  398. // The “shape” parameter specifies the requested shape. The
  399. // return value specifies that shape as it is obscured by the
  400. // other contents of this part.
  401.  
  402. {
  403.     ODTransform*    xform        = kODNULL;
  404.     ODFacet*        rootFacet;
  405.     
  406.     if ( embeddedFacet == kODNULL )
  407.         THROW(kODErrIllegalNullInput);        // $$$$$ kODErrIllegalNullFacetInput
  408.     
  409.     ODReleaseObject (ev, fActiveBorderShape);
  410.  
  411.     if (shape != kODNULL)
  412.     {
  413.     
  414.         if (fCAAdjustBorderHook && fCAAdjustBorderHandler)
  415.         {
  416.     
  417.             fCAAdjustBorderHook (    fCAAdjustBorderHandler,
  418.                                     fSelf->GetStorageUnit(ev)->GetDraft(ev),
  419.                                     embeddedFacet->GetFrame(ev),
  420.                                     shape);
  421.                                     
  422.         
  423.         }
  424.     
  425.         ODAcquireObject(ev, shape);
  426.         
  427.         xform = embeddedFacet->AcquireWindowFrameTransform(ev, kNoBias);
  428.  
  429.         fActiveBorderShape = shape->Copy(ev);
  430.         fActiveBorderShape->Transform (ev, xform);
  431.  
  432.         ODRelease (ev, xform);
  433.         
  434.     }
  435.  
  436.     
  437.     rootFacet = embeddedFacet;
  438.     if (rootFacet->GetContainingFacet(ev) != kODNULL)
  439.     {
  440.         rootFacet = rootFacet->GetContainingFacet(ev);
  441.     }
  442.         
  443.  
  444.     return shape;
  445.  
  446. }
  447.  
  448. //--------------------------------------------------------------------
  449. // CAProxyPart::AdjustMenus
  450. //--------------------------------------------------------------------
  451.  
  452. void CAProxyPart::AdjustMenus(Environment* ev, ODFrame* frame)
  453. {
  454. ODUnused (ev);
  455. ODUnused (frame);
  456.  
  457. }
  458.  
  459.     
  460.  
  461. //-------------------------------------------------------------------------
  462. // CAProxyPart::BeginRelinquishFocus
  463. //-------------------------------------------------------------------------
  464.  
  465. ODBoolean CAProxyPart::BeginRelinquishFocus(Environment* ev, ODTypeToken focus,
  466.                                               ODFrame* ownerFrame,
  467.                                               ODFrame* proposedFrame)
  468. {
  469. ODUnused(ev);
  470. ODUnused(ownerFrame);
  471. ODUnused(focus);
  472. ODUnused(proposedFrame);
  473.  
  474.     return kODTrue;
  475. }
  476.  
  477. //-------------------------------------------------------------------------
  478. // Imaging protocol
  479. //-------------------------------------------------------------------------
  480.  
  481. void CAProxyPart::CanvasUpdated(Environment* ev, ODCanvas* canvas)
  482.  
  483. {
  484.     if (this->fCACanvasUpdatedHandler)
  485.     {
  486.         CallUniversalProc(fCACanvasUpdatedHandler, uppCACanvasUpdatedProcInfo,
  487.                                 canvas->GetQDPort(ev));
  488.     }
  489. }
  490.  
  491.  
  492. //-------------------------------------------------------------------------
  493. // Storage protocol
  494. //-------------------------------------------------------------------------
  495.  
  496. void CAProxyPart::CloneInto(Environment* ev, ODDraftKey key,
  497.                                 ODStorageUnit* toSU, ODFrame* scope)
  498.  
  499.  
  500. {
  501.     ODID                scopeID = 0;
  502.  
  503.     if (scope)
  504.         scopeID = scope->GetID(ev);
  505.     
  506.     // Clone our SU
  507.     fSelf->GetStorageUnit(ev)->CloneInto (ev, key, toSU, scopeID);
  508.         
  509. }
  510.  
  511. //-------------------------------------------------------------------------
  512. // CAProxyPart::CommitRelinquishFocus
  513. //-------------------------------------------------------------------------
  514.  
  515. void CAProxyPart::CommitRelinquishFocus(Environment* ev, ODTypeToken focus, ODFrame* ownerFrame,
  516.                                                          ODFrame* proposedFrame)
  517. {
  518.  
  519. ODUnused(proposedFrame);
  520.  
  521.     
  522.     if ( (focus == gSelectionFocus)) // && fEmbeddedFrames->Contains (proposedFrame))
  523.     {
  524.     
  525.  
  526.         //ODAcquireObject (ev, proposedFrame);
  527.         //fActiveFrame = proposedFrame;
  528.  
  529.     }
  530.     
  531.     this->FocusLost(ev, focus, ownerFrame);
  532.         // •• 6/23/94
  533.         // No choices to be made here.  It's too late to say no.  We are
  534.         // losing the focus if we are here.  Getting called here means
  535.         // that BeginRelinquishFocus has already agreed that losing focus
  536.         // is okay.  If you don't want this to be happening, then you need
  537.         // to do something in BeginRelinquishFocus.
  538.         //
  539.         // The way that some other samples are currently written I believe
  540.         // to be in error.  The recipes say that when this is called, it
  541.         // has already been decided that, focus-wise, you lose.  Therefore
  542.         // there should be no conditions on calling FocusLost.
  543. }
  544.                             
  545.  
  546. //-------------------------------------------------------------------------
  547. // CAProxyPart::CreateEmbeddedFramesIterator
  548. //-------------------------------------------------------------------------
  549.  
  550. ODEmbeddedFramesIterator* CAProxyPart::CreateEmbeddedFramesIterator(Environment *ev,
  551.         ODFrame* frame)
  552. {
  553.  
  554.     CAProxyEmbeddedFramesIterator* iter = new CAProxyEmbeddedFramesIterator;
  555.     iter->InitEmbeddedFramesIterator(ev, (ODPart*) this);
  556.  
  557.     return iter;
  558. }
  559.  
  560.  
  561. //-------------------------------------------------------------------------
  562. // CAProxyPart::DisplayFrameAdded
  563. //-------------------------------------------------------------------------
  564.  
  565. void CAProxyPart::DisplayFrameAdded(Environment *ev,
  566.         ODFrame* frame)
  567. {
  568.  
  569.     OrderedCollectionIterator*    iter;
  570.     ODSession* session = fSelf->GetStorageUnit(ev)->GetSession(ev);
  571.     CFrameInfo*                    frameInfo;
  572.     
  573.     iter = fEmbeddedFrames->CreateIterator();
  574.  
  575.     for (frameInfo = (CFrameInfo*)iter->First();
  576.             iter->IsNotComplete(); 
  577.             frameInfo = (CFrameInfo*)iter->Next())
  578.     {
  579.         frameInfo->GetFrame()->SetContainingFrame(ev, frame);
  580.     }
  581.  
  582.     ODDeleteObject (iter);
  583.     
  584.     CDisplayFrameInfo* displayFrameInfo = new CDisplayFrameInfo (ev, frame);
  585.     
  586.     //frameInfo->Internalize();
  587.     //frameInfo->Externalize(fSelf->GetStorageUnit(ev));    // Keep a su ref for the root frame with the other frame refs
  588.     fDisplayFrame = displayFrameInfo;
  589.     
  590.     if (frame->GetViewType(ev) == kODNullTypeToken)                        // if frame view is set don't change it
  591.         frame->SetViewType(ev, session->Tokenize(ev, kODViewAsFrame));        // if not, make it viewasframe
  592.     if (frame->GetPresentation(ev) == kODNullTypeToken)                    
  593.         frame->SetPresentation(ev, session->Tokenize(ev, kCAProxyPartPresNormal));
  594.  
  595.     PartInfo*    partInfo = new PartInfo;
  596.     fDisplayFrame->GetFrame()->SetPartInfo (ev, (ODInfoType) partInfo);
  597.     
  598. }
  599.  
  600. //-------------------------------------------------------------------------
  601. // CAProxyPart::DisplayFrameClosed
  602. //-------------------------------------------------------------------------
  603.  
  604. void CAProxyPart::DisplayFrameClosed(Environment* ev, ODFrame* frame)
  605.  
  606. // Informs a part that one of its display frames is closing.
  607. //
  608. // Called by the frame object.
  609. // The part should remove “frame” from its list of display frames,
  610. // call Frame::Close() on any frames that are embedded within that
  611. // frame, and then release the frame.
  612.  
  613. {
  614.  
  615.     ODSession*                    session = fSelf->GetStorageUnit(ev)->GetSession(ev);
  616.     OrderedCollectionIterator*    iter;
  617.     CFrameInfo*                    frameInfo;
  618.  
  619.     session->GetArbitrator(ev)->RelinquishFocusSet(ev, gUIFocusSet, frame);
  620.  
  621.     frameInfo = (CFrameInfo*) fEmbeddedFrames->First();
  622.         
  623.      iter = fEmbeddedFrames->CreateIterator();
  624.  
  625.     for (frameInfo = (CFrameInfo*)iter->First();
  626.             iter->IsNotComplete(); 
  627.             frameInfo = (CFrameInfo*)iter->Next())
  628.     {
  629.         frameInfo->Close();
  630.     }
  631.     
  632.     ODDeleteObject (iter);
  633.  
  634.     PartInfo*    partInfo = (PartInfo*) fDisplayFrame->GetFrame()->GetPartInfo(ev);
  635.     fDisplayFrame->GetFrame()->SetPartInfo (ev, (ODInfoType) kODNULL);
  636.     ODDeleteObject (partInfo);
  637.  
  638.     if (frame != fDisplayFrame->GetFrame())
  639.         DebugStr ("\p CAProxyPart::DisplayFrameClosed - close what?");
  640.         
  641.     ODDeleteObject (fDisplayFrame);
  642.     fDisplayFrame = NULL;
  643.  
  644. }
  645.  
  646.  
  647.  
  648. //-------------------------------------------------------------------------
  649. // CAProxyPart::DisplayFrameConnected
  650. //-------------------------------------------------------------------------
  651.  
  652. void CAProxyPart::DisplayFrameConnected(    Environment*    ev,
  653.                                             ODFrame*        frame )
  654. {
  655.  
  656.     CFrameInfo*                    frameInfo;
  657.     OrderedCollectionIterator*    iter;
  658.  
  659.     if ((fDisplayFrame) && (fDisplayFrame->GetFrame() != frame))
  660.     {
  661.         DebugStr ("\pUnknown displayframe connected"); 
  662.     }
  663.     
  664.     if (!fDisplayFrame)
  665.     {
  666.         fDisplayFrame = new CDisplayFrameInfo (ev, frame);
  667.     }
  668.     
  669.      iter = fEmbeddedFrames->CreateIterator();
  670.  
  671.     for (frameInfo = (CFrameInfo*)iter->First();
  672.             iter->IsNotComplete(); 
  673.             frameInfo = (CFrameInfo*)iter->Next())
  674.     {
  675.         frameInfo->GetFrame()->SetContainingFrame(ev, frame);
  676.     }
  677.     
  678.     ODDeleteObject (iter);
  679.  
  680.     
  681. }
  682.  
  683. //-------------------------------------------------------------------------
  684. // CAProxyPart::DisplayFrameRemoved
  685. //-------------------------------------------------------------------------
  686.  
  687. void CAProxyPart::DisplayFrameRemoved(Environment *ev,
  688.         ODFrame* frame)
  689. {
  690.     CFrameInfo*            frameInfo;
  691.     ODSession*            session = fSelf->GetStorageUnit(ev)->GetSession(ev);
  692.  
  693.     session->GetArbitrator(ev)->RelinquishFocusSet(ev, gUIFocusSet, frame);
  694.  
  695.     frameInfo = (CFrameInfo*) fEmbeddedFrames->First();
  696.         
  697.     while (frameInfo != kODNULL)
  698.     {
  699.         
  700.         fEmbeddedFrames->Remove(frameInfo);
  701.         frameInfo->Remove();
  702.         delete frameInfo;
  703.         frameInfo = (CFrameInfo*) fEmbeddedFrames->First();
  704.         
  705.     }
  706.  
  707.     if (frame != fDisplayFrame->GetFrame())
  708.         DebugStr ("\p CAProxyPart::DisplayFrameClosed error");
  709.         
  710.     PartInfo*    partInfo = (PartInfo*) fDisplayFrame->GetFrame()->GetPartInfo(ev);
  711.     fDisplayFrame->GetFrame()->SetPartInfo (ev, (ODInfoType) kODNULL);
  712.     ODDeleteObject (partInfo);
  713.     
  714.     ODDeleteObject (fDisplayFrame);
  715.     fDisplayFrame = NULL;
  716.  
  717. }
  718.  
  719.  
  720. //--------------------------------------------------------------------
  721. // CAProxyPart::Draw
  722. //--------------------------------------------------------------------
  723.  
  724. void CAProxyPart::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
  725. {
  726. ODUnused(ev);
  727. ODUnused(facet);
  728. ODUnused(invalidShape);
  729. }
  730.  
  731.  
  732. //--------------------------------------------------------------------
  733. // CAProxyPart::ExternalizeKinds
  734. //--------------------------------------------------------------------
  735.  
  736. void CAProxyPart::ExternalizeKinds(Environment* ev, ODTypeList* kindList)
  737. {
  738. ODUnused(ev);
  739. ODUnused(kindList);
  740. }
  741.  
  742.  
  743.  
  744.  
  745.  
  746. //--------------------------------------------------------------------
  747. // CAProxyPart::Externalize
  748. //--------------------------------------------------------------------
  749.  
  750. void    CAProxyPart::Externalize(Environment* ev)
  751. {
  752.     
  753.     // Flag our part as no longer being dirty.
  754.  
  755.     if ( fDirty && !fReadOnlyStorage)
  756.         fDirty = kODFalse;
  757.     
  758. }
  759.  
  760. //-------------------------------------------------------------------------
  761. // Facet protocol
  762. //-------------------------------------------------------------------------
  763.  
  764. void CAProxyPart::FacetAdded(Environment* ev, ODFacet* facet)
  765. {
  766.     
  767.     // Add new facet to list of current facets.
  768.     fFacets.Add(facet);
  769.  
  770. }
  771.  
  772.  
  773. void CAProxyPart::FacetRemoved(Environment* ev, ODFacet* facet)
  774. {
  775.  
  776.     fFacets.Remove(facet);
  777.     // This just removes the reference from our facet list.
  778.  
  779.     OrderedCollection* children = new OrderedCollection;
  780.     ODFacetIterator* facets = facet->CreateFacetIterator(ev, kODChildrenOnly, kODFrontToBack);
  781.     ODFacet* childFacet;
  782.     for (childFacet = facets->First(ev);
  783.         facets->IsNotComplete(ev);
  784.         childFacet = facets->Next(ev))
  785.     {
  786.         children->AddLast(childFacet);
  787.     }
  788.     delete facets;
  789.  
  790.     OrderedCollectionIterator iter(children);
  791.     for (childFacet = (ODFacet*)iter.First();
  792.             iter.IsNotComplete();
  793.             childFacet = (ODFacet*)iter.Next())
  794.     {
  795.         facet->RemoveFacet(ev, childFacet);
  796.         delete childFacet;
  797.     }
  798.     delete children;
  799. }
  800.  
  801. //-------------------------------------------------------------------------
  802. // CAProxyPart::FocusAcquired
  803. //-------------------------------------------------------------------------
  804.                               
  805. void CAProxyPart::FocusAcquired(Environment* ev, ODTypeToken focus, ODFrame* ownerFrame)
  806. {
  807. ODUnused(ev);
  808. ODUnused(ownerFrame);
  809.  
  810.     PartInfo*    partInfo;
  811.  
  812.     if (focus == gSelectionFocus)
  813.     {
  814.         partInfo = (PartInfo*) ownerFrame->GetPartInfo(ev);
  815.         partInfo->SetFrameActive (kODTrue);
  816.     }
  817.     
  818.     if (fCAFocusAquiredHandler)
  819.     {
  820.         if (focus == gSelectionFocus)
  821.         {
  822.             CallUniversalProc(fCAFocusAquiredHandler, uppCAFocusAcquiredProcInfo,
  823.                                 fCADocumentRef, kCAPrimaryFocus);
  824.         }
  825.     }
  826. }    
  827.  
  828. //-------------------------------------------------------------------------
  829. // CAProxyPart::FocusLost
  830. //-------------------------------------------------------------------------
  831.  
  832. void CAProxyPart::FocusLost(Environment* ev, ODTypeToken focus, ODFrame* ownerFrame)
  833. {
  834. ODUnused(ev);
  835. ODUnused(ownerFrame);
  836.  
  837.     PartInfo*        partInfo;
  838.     ODFrame*        focusFrame    = kODNULL;
  839.     ODSession*        session        = fSelf->GetStorageUnit(ev)->GetSession(ev);
  840.  
  841.     if (focus == gSelectionFocus)
  842.     {
  843.         partInfo = (PartInfo*) ownerFrame->GetPartInfo(ev);
  844.         partInfo->SetFrameActive (kODFalse);
  845.  
  846.         if (fCAFocusLostHandler)
  847.         {
  848.     
  849.             CallUniversalProc(fCAFocusLostHandler, uppCAFocusLostProcInfo,
  850.                                 fCADocumentRef, kCAPrimaryFocus);
  851.     
  852.         }
  853.  
  854.     }
  855.  
  856.  
  857. }
  858.  
  859. //-------------------------------------------------------------------------
  860. // CAProxyPart::FrameShapeChanged
  861. //-------------------------------------------------------------------------
  862.  
  863. void CAProxyPart::FrameShapeChanged(Environment* ev, ODFrame* frame)
  864. {
  865.  
  866.     ODFacet*        rootFacet;
  867.     ODWindow*        window;
  868.     ODShape*         clipShape;
  869.  
  870.     window = frame->AcquireWindow(ev);
  871.     rootFacet = window->GetRootFacet(ev);
  872.     ODReleaseObject (ev, window);
  873.     
  874.     if (rootFacet)
  875.     {
  876.         clipShape = ODCopyAndRelease (ev, frame->AcquireFrameShape(ev, kODNULL));
  877.  
  878.         rootFacet->ChangeGeometry (ev, clipShape, kODNULL, kODNULL);
  879.         ODReleaseObject (ev, clipShape);
  880.     }
  881. }
  882.  
  883.  
  884. //-------------------------------------------------------------------------
  885. // UI Events protocol
  886. //-------------------------------------------------------------------------
  887.  
  888. ODBoolean CAProxyPart::HandleEvent(Environment* ev, ODEventData* event,
  889.                                      ODFrame* frame, ODFacet* facet, ODEventInfo* eventInfo)
  890. {
  891.  
  892.     ODBoolean    tWasHandled = kODFalse;
  893.  
  894.     fLastEventInfo = *eventInfo;
  895.  
  896.     switch ( event->what )
  897.     {
  898.         case nullEvent:
  899.             break;
  900.             
  901.         case mouseDown:
  902.             break;
  903.  
  904.         case mouseUp:
  905.         case keyDown:
  906.         case autoKey:
  907.             tWasHandled = kODFalse;
  908.             break;
  909.  
  910.         case kODEvtActivate:
  911.             tWasHandled = this->UTIL_HandleActivateEvent (ev, frame, event);
  912.             break;
  913.  
  914.         case kODEvtMenu:
  915.             break;
  916.  
  917.         case kODEvtMouseDownEmbedded:
  918.             break;
  919.         
  920.         case kODEvtMouseDownBorder:
  921.             break;
  922.  
  923.         case kODEvtMouseUpEmbedded:
  924.             break;
  925.  
  926.         case kODEvtBGMouseDownEmbedded:
  927.             break;
  928.  
  929.         default:
  930.             break;
  931.     }
  932.  
  933.     return tWasHandled;
  934.  
  935. }
  936.  
  937. void CAProxyPart::HighlightChanged(Environment* ev, ODFacet* facet)
  938. {
  939. ODUnused(ev);
  940. ODUnused(facet);
  941. }
  942.  
  943.  
  944. //--------------------------------------------------------------------
  945. // CAProxyPart::InitPart
  946. //--------------------------------------------------------------------
  947.  
  948. void CAProxyPart::InitPart(Environment* ev, ODStorageUnit* storageUnit, ODPart* partWrapper)
  949. {
  950.     fSelf                = partWrapper;
  951.     fReadOnlyStorage    = kODFalse;
  952.  
  953.     this->UTIL_CleanseContentProperty (ev, storageUnit);
  954.     this->UTIL_CheckAndAddProperties (ev, storageUnit);
  955.     this->UTIL_CommonInitPart (ev);
  956.     this->UTIL_SetDirty (ev);
  957.  
  958. }
  959.  
  960.  
  961. //--------------------------------------------------------------------
  962. // CAProxyPart::InitPartFromStorage
  963. //--------------------------------------------------------------------
  964.  
  965. void CAProxyPart::InitPartFromStorage(Environment* ev, ODStorageUnit* storageUnit, ODPart* partWrapper)
  966. {
  967.  
  968.     fSelf                = partWrapper;
  969.     fReadOnlyStorage    = ( storageUnit->GetDraft(ev)->GetPermissions(ev) == kODDPReadOnly );
  970.  
  971.     this->UTIL_CommonInitPart(ev);
  972.     this->UTIL_InternalizeContent (ev, storageUnit);
  973.     this->UTIL_SetDirty (ev);
  974.  
  975. }
  976.  
  977.  
  978. //--------------------------------------------------------------------
  979. // CAProxyPart::Open
  980. //--------------------------------------------------------------------
  981.  
  982. ODID  CAProxyPart::Open(Environment* ev, ODFrame* frame)
  983. {
  984. ODUnused (ev);
  985. ODUnused (frame);
  986.  
  987.     return (0);
  988. }
  989.  
  990.  
  991. //-------------------------------------------------------------------------
  992. // CAProxyPart::Purge
  993. //-------------------------------------------------------------------------
  994.  
  995. ODSize CAProxyPart::Purge(Environment* ev, ODSize size)
  996. {
  997. ODUnused(ev);
  998. ODUnused(size);
  999.     
  1000.     return 0L;
  1001. }
  1002.  
  1003.  
  1004.  
  1005. //-------------------------------------------------------------------------
  1006. // CAProxyPart::Release
  1007. //-------------------------------------------------------------------------
  1008.  
  1009. void CAProxyPart::Release(Environment* ev)
  1010. {
  1011.     
  1012.     if (fSelf->GetRefCount(ev) == 1)
  1013.         return;
  1014.     if (fSelf->GetRefCount(ev) == 0)
  1015.         fSelf->GetStorageUnit(ev)->GetDraft(ev)->ReleasePart(ev, fSelf);
  1016. }
  1017.  
  1018.  
  1019. //--------------------------------------------------------------------
  1020. // CAProxyPart::ReleaseAll
  1021. //--------------------------------------------------------------------
  1022.  
  1023. void    CAProxyPart::ReleaseAll(Environment* ev)
  1024. {
  1025.  
  1026.     CFrameInfo*    frameInfo;
  1027.     
  1028.     TRY
  1029.     
  1030.         if (fEmbeddedFrames)
  1031.         {
  1032.         
  1033.             frameInfo = (CFrameInfo*) fEmbeddedFrames->First();
  1034.         
  1035.             while (frameInfo != kODNULL)
  1036.             {
  1037.         
  1038.                 fEmbeddedFrames->Remove(frameInfo);
  1039.                 //frameInfo->GetFrame()->Release(ev);
  1040.                 delete frameInfo;
  1041.                 frameInfo = (CFrameInfo*) fEmbeddedFrames->First();
  1042.         
  1043.             }
  1044.  
  1045.         }
  1046.         
  1047.         ODDeleteObject (fEmbeddedFrames);
  1048.         ODDeleteObject (fDisplayFrame);
  1049.         
  1050.         ODFinalReleaseObject (ev, fProxyExt);
  1051.         ODFinalReleaseObject (ev, fActiveBorderShape);
  1052.         
  1053.         // If the last part instance using the globals is released,
  1054.         // we need to NULL out the globals.
  1055.         
  1056.         if ( --gGlobalsUsageCount == 0 )
  1057.         {
  1058.             // We can't delete the MenuBar because it is shared by multiple
  1059.             // clients, and we're not going to assume they are done with it.
  1060.             gMenuBar = kODNULL;
  1061.             
  1062.             // On the other hand, the FocusSet is not shared and deleting it
  1063.             // is the right thing to do.
  1064.             if ( gUIFocusSet )
  1065.             {
  1066.                 delete gUIFocusSet;
  1067.                 gUIFocusSet = kODNULL;
  1068.             }
  1069.         }
  1070.                         
  1071.     SOM_ENDTRY
  1072.  
  1073.     
  1074. }
  1075.  
  1076.  
  1077. //------------------------------------------------------------------------------
  1078. // CAProxyPart::RemoveEmbeddedFrame
  1079. //------------------------------------------------------------------------------
  1080.  
  1081. void CAProxyPart::RemoveEmbeddedFrame(Environment *ev,
  1082.         ODFrame* embeddedFrame)
  1083. {
  1084.     ODFrame*                containingFrame;
  1085.     ODFrameFacetIterator*    facets;
  1086.     ODFacet*                embFacet;    
  1087.     CFrameInfo*                targetFrameInfo = kODNULL;
  1088.  
  1089.     containingFrame = embeddedFrame->AcquireContainingFrame(ev);
  1090.         
  1091.     facets = embeddedFrame->CreateFacetIterator(ev);
  1092.             
  1093.     for (embFacet = facets->First(ev);
  1094.             facets->IsNotComplete(ev);
  1095.             embFacet = facets->Next(ev))
  1096.     {
  1097.         ODDeleteObject (embFacet);
  1098.     }
  1099.             
  1100.     ODDeleteObject (facets);
  1101.     
  1102.     targetFrameInfo = this->UTIL_FindFrameInfoForFrame (ev, embeddedFrame);
  1103.     
  1104.     if (targetFrameInfo)
  1105.     {
  1106.         fEmbeddedFrames->Remove(targetFrameInfo);
  1107.         embeddedFrame->Remove(ev);
  1108.         delete targetFrameInfo;
  1109.     }
  1110.     
  1111.     containingFrame->Release(ev);
  1112.  
  1113. }
  1114.  
  1115.  
  1116. //-------------------------------------------------------------------------
  1117. // CAProxyPart::RequestFrameShape
  1118. //-------------------------------------------------------------------------
  1119.  
  1120. ODShape* CAProxyPart::RequestFrameShape(Environment *ev,
  1121.         ODFrame* embeddedFrame,
  1122.         ODShape* frameShape)
  1123. {
  1124.     ODShape*    shapeCopy;
  1125.     
  1126.     shapeCopy = frameShape->Copy(ev);
  1127.     
  1128.     if (fCAFrameShapeRequestHandler && fCAFrameShapeRequestHook)
  1129.     {
  1130.     
  1131.         fCAFrameShapeRequestHook (    fCAFrameShapeRequestHandler,
  1132.                                     fSelf->GetStorageUnit(ev)->GetDraft(ev),
  1133.                                     embeddedFrame, shapeCopy);
  1134.     }
  1135.     
  1136.     return shapeCopy;
  1137. }
  1138.  
  1139.  
  1140. //--------------------------------------------------------------------
  1141. // CAProxyPart::UsedShapeChanged
  1142. //--------------------------------------------------------------------
  1143.  
  1144. void CAProxyPart::UsedShapeChanged(Environment *ev,
  1145.         ODFrame* embeddedFrame)
  1146. {
  1147.     TempODFrame containingFrame = embeddedFrame->AcquireContainingFrame(ev);
  1148.     embeddedFrame->Invalidate (ev, kODNULL, kODNULL);
  1149. }
  1150.  
  1151.  
  1152.  
  1153. //--------------------------------------------------------------------
  1154. // CAProxyPart::UTIL_CleanseContentProperty
  1155. //--------------------------------------------------------------------
  1156.  
  1157. void CAProxyPart::UTIL_CleanseContentProperty(    Environment* ev,
  1158.                                                 ODStorageUnit* storageUnit)
  1159. {
  1160.     ODULong numValues;
  1161.     ODULong index;
  1162.     
  1163.     if (storageUnit->Exists (ev, kODPropContents, kODNULL, kODPosFirstSib))
  1164.     {
  1165.     
  1166.         storageUnit->Focus(ev, kODPropContents, kODPosUndefined, 
  1167.                             kODNULL, 0, kODPosAll);
  1168.     
  1169.         numValues = storageUnit->CountValues(ev);
  1170.     
  1171.         for (index = numValues; index >= 1; index--)
  1172.         {
  1173.             // Index from 1 to n through the values.
  1174.             storageUnit->Focus(ev, kODPropContents, kODPosUndefined, 
  1175.                                 kODNULL, index, kODPosUndefined);
  1176.             storageUnit->Remove(ev);
  1177.             
  1178.         }
  1179.         
  1180.     }
  1181.  
  1182. }
  1183.     
  1184. //--------------------------------------------------------------------
  1185. // CAProxyPart::UTIL_CheckAndAddProperties
  1186. //--------------------------------------------------------------------
  1187.  
  1188. void CAProxyPart::UTIL_CheckAndAddProperties(    Environment*    ev,
  1189.                                                 ODStorageUnit*    storageUnit )
  1190. {
  1191.  
  1192.     // Create our content property and preferred content property kind.
  1193.  
  1194.     if ( !storageUnit->Exists(ev, kCAPropEmbeddedFrames, kODNULL, 0) )
  1195.         storageUnit->AddProperty(ev, kCAPropEmbeddedFrames);
  1196.     if (!storageUnit->Exists (ev, kCAPropEmbeddedFrames, kODNULL, 1))
  1197.         storageUnit->AddValue(ev, kODStrongStorageUnitRefs);
  1198.     
  1199.     // Only add a kCAProxyPartKind value if the kODPropContents property
  1200.     // is empty
  1201.     
  1202.     // Add our display frame list.
  1203.     
  1204.     if ( !storageUnit->Exists(ev, kODPropDisplayFrames, kODNULL, 0) )
  1205.         storageUnit->AddProperty(ev, kODPropDisplayFrames);
  1206.     if ( !storageUnit->Exists(ev, kODPropDisplayFrames, kODWeakStorageUnitRefs, 0) )
  1207.         storageUnit->AddValue(ev, kODWeakStorageUnitRefs);
  1208.  
  1209.     if ( !storageUnit->Exists(ev, kODPropPreferredKind, kODNULL, 0) )
  1210.         storageUnit->AddProperty(ev, kODPropPreferredKind);
  1211.     if ( !storageUnit->Exists(ev, kODPropPreferredKind, kODISOStr, 0) )
  1212.     {
  1213.         storageUnit->AddValue(ev, kODISOStr);
  1214.         
  1215.         // Since we are setting up the preferred kind property, we just write
  1216.         // out our default "kind" for the editor. We can write out the user
  1217.         // chosen kind in the ExternalizeStateInfo method.
  1218.  
  1219.         TRY
  1220.             StorageUnitSetValue(storageUnit, ev, ODISOStrLength(kCAProxyPartKind) + 1,
  1221.                                 kCAProxyPartKind);
  1222.         SOM_ENDTRY
  1223.     }
  1224.  
  1225.     // Parts by default have no name, though one is visible from 
  1226.     // the part info dialog and is required during Drag&Drop to the
  1227.     // Finder. We check for existence of the name property. If there
  1228.     // is none, we add it; if there is, we focus to it.
  1229.     
  1230.     if ( !storageUnit->Exists(ev, kODPropName, kODMacIText, 0) )
  1231.     {
  1232.         storageUnit->AddProperty(ev, kODPropName)->AddValue(ev, kODMacIText);
  1233.     
  1234.         // Generate a default name for the part using the category
  1235.         // user string.
  1236.         ODIText*    defaultName;
  1237.         
  1238.         defaultName = CreateITextCString (smRoman, langEnglish, kCAProxyPartKindUserString);
  1239.         
  1240.         ODSetITextProp(ev, storageUnit, kODPropName, kODMacIText, defaultName);
  1241.  
  1242.     }
  1243.  
  1244.  
  1245. }
  1246.  
  1247. //--------------------------------------------------------------------
  1248. // CAProxyPart::UTIL_InternalizeContent
  1249. //--------------------------------------------------------------------
  1250.     
  1251. void CAProxyPart::UTIL_InternalizeContent(    Environment* ev,
  1252.                                             ODStorageUnit* storageUnit)
  1253. {
  1254.  
  1255.     ODStorageUnitRef            aSURef;
  1256.     ODID                        frameID;
  1257.     ODStorageUnitRefIterator*    frameIter;
  1258.     CFrameInfo*                    frameInfo;
  1259.     ODSize                        size;
  1260.     ODStorageUnitRef            ref;
  1261.  
  1262.     if (!storageUnit->Exists (ev, kCAPropEmbeddedFrames, kODStrongStorageUnitRefs, 0))
  1263.         DebugStr ("\pCAProxyPart::UTIL_InternalizeContent - no embedded frames");
  1264.     
  1265.     ODSUExistsThenFocus (ev, storageUnit, kCAPropEmbeddedFrames, kODStrongStorageUnitRefs);
  1266.  
  1267.     ODSize streamSize = storageUnit->GetSize(ev);
  1268.  
  1269.     frameIter = storageUnit->CreateStorageUnitRefIterator (ev);
  1270.  
  1271.     for (frameIter->First(ev, aSURef);
  1272.          frameIter->IsNotComplete(ev);
  1273.         frameIter->Next(ev, aSURef))
  1274.     {
  1275.  
  1276.         frameID = storageUnit->GetIDFromStorageUnitRef (ev, aSURef);
  1277.         frameInfo = new CFrameInfo (ev, frameID, storageUnit->GetDraft(ev));
  1278.         frameInfo->Internalize();
  1279.         
  1280.         TRACE (3, "InteralizeContent - frame %x, frameID %d, ref %x",
  1281.                     frameInfo->GetFrame(), frameID, *aSURef);
  1282.         
  1283.         fEmbeddedFrames->AddLast (frameInfo);
  1284.  
  1285.     }
  1286.     
  1287.     ODDeleteObject (frameIter);
  1288.     
  1289.  
  1290. }
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296. //--------------------------------------------------------------------
  1297. // CAProxyPart::UTIL_FindFrameInfoForFrame
  1298. //--------------------------------------------------------------------
  1299.  
  1300. CFrameInfo*    CAProxyPart::UTIL_FindFrameInfoForFrame( Environment *ev, ODFrame* frame)
  1301. {
  1302.  
  1303.     CFrameInfo*                    frameInfo = kODNULL;
  1304.     CFrameInfo*                    targetFrameInfo = kODNULL;
  1305.     OrderedCollectionIterator*    iter;
  1306.  
  1307.     iter = fEmbeddedFrames->CreateIterator();
  1308.  
  1309.     for (frameInfo = (CFrameInfo*)iter->First();
  1310.             iter->IsNotComplete(); 
  1311.             frameInfo = (CFrameInfo*)iter->Next())
  1312.     {
  1313.         if (frameInfo->GetFrame() == frame)
  1314.         {
  1315.             targetFrameInfo = frameInfo;
  1316.             break;
  1317.         }
  1318.             
  1319.     }
  1320.     
  1321.     ODDeleteObject (iter);
  1322.     
  1323.     return (targetFrameInfo);
  1324.     
  1325.  
  1326. }
  1327.  
  1328.  
  1329. //--------------------------------------------------------------------
  1330. // CAProxyPart::UTIL_ActivateDisplayFrame
  1331. //--------------------------------------------------------------------
  1332.  
  1333. void CAProxyPart::UTIL_ActivateDisplayFrame(Environment *ev,
  1334.         ODFrame* frame)
  1335. {
  1336.     ODMenuBar*            menuBar = kODNULL;
  1337.     ODSession* session = fSelf->GetStorageUnit(ev)->GetSession(ev);
  1338.  
  1339.     
  1340.     PartInfo*    partInfo = (PartInfo*) frame->GetPartInfo(ev);
  1341.  
  1342.     if (!partInfo->IsFrameActive())
  1343.     {
  1344.         // Request the set of foci necessary to become active.
  1345.         if ( session->GetArbitrator(ev)->RequestFocusSet(ev, gUIFocusSet, frame) )
  1346.         {
  1347.         
  1348.             // Notify ourself that we acquired the selection and menu foci. 
  1349.             this->FocusAcquired(ev, gSelectionFocus, frame);
  1350.             this->FocusAcquired(ev, gMenuFocus, frame);
  1351.             this->FocusAcquired(ev, gKeyFocus, frame);
  1352.                 
  1353.         }
  1354.     }        
  1355.         
  1356.     // We sucessfully acquired the foci we need to be active.
  1357.  
  1358. }
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366. //--------------------------------------------------------------------
  1367. // CAProxyPart::UTIL_CommonInitPart
  1368. //--------------------------------------------------------------------
  1369.  
  1370. void CAProxyPart::UTIL_CommonInitPart(Environment* ev)
  1371. {
  1372.  
  1373.     ODSession* session = fSelf->GetStorageUnit(ev)->GetSession(ev);
  1374.  
  1375.     if ( gGlobalsUsageCount == 0 )
  1376.     {
  1377.         // It is required that parts instantiate their menu bars from 
  1378.         // the base OpenDoc menu bar. This maintains consistency in the
  1379.         // default menu items and their placement.
  1380.         // Since the object is a copy, we can add and subtract menus and
  1381.         // items without affecting other running parts.
  1382.         //gMenuBar = session->GetWindowState(ev)->CopyBaseMenuBar(ev);
  1383.  
  1384.         // We will be using the following foci (shared resources) in this
  1385.         // part. For convenience, we tokenize the values here and store
  1386.         // them for equivalence tests in the activation methods.
  1387.         gSelectionFocus = session->Tokenize(ev, kODSelectionFocus);
  1388.         gMenuFocus      = session->Tokenize(ev, kODMenuFocus);
  1389.         gModalFocus     = session->Tokenize(ev, kODModalFocus);
  1390.         gKeyFocus       = session->Tokenize(ev, kODKeyFocus);
  1391.         gClipboardFocus    = session->Tokenize(ev, kODClipboardFocus);
  1392.         
  1393.         // Lastly, we will package the menu and selection focus
  1394.         // so that we can request the "set" at activation time.
  1395.         gUIFocusSet = session->GetArbitrator(ev)->CreateFocusSet(ev);
  1396.         gUIFocusSet->Add(ev, gMenuFocus);
  1397.         gUIFocusSet->Add(ev, gSelectionFocus);
  1398.         gUIFocusSet->Add(ev, gKeyFocus);
  1399.             
  1400.         // Determine what Script/Language the part is localized for.
  1401.         // This is important/necessary for creating OpenDoc's text objects.
  1402.         //GetEditorScriptLanguage(ev, &gPartsScript, &gPartsLanguage);
  1403.         
  1404.         // The first client of the global variables is running.
  1405.         gGlobalsUsageCount = 1;
  1406.     }
  1407.     else
  1408.     // If the globals have been initialized, we just bump the refcount of the
  1409.     // menu bar. This prevents will prevent it from going away before we are
  1410.     // done using it. We also keep a "usage" count so that we can null out the
  1411.     // global variables when we are finished using them.
  1412.     {
  1413.         //ODAcquireObject (ev, gMenuBar);;
  1414.         gGlobalsUsageCount++;
  1415.     }
  1416.  
  1417.     fEmbeddedFrames = new OrderedCollection;
  1418.  
  1419.     // Get the interface extension object for CALib callback support
  1420.     // and initialize it
  1421.     
  1422.     fProxyExt = new CAProxyExtension;
  1423.     fProxyExt->InitProxyExtension( ev, fSelf, this );
  1424.     
  1425.  
  1426. }
  1427.  
  1428.  
  1429. //--------------------------------------------------------------------
  1430. // CAProxyPart::UTIL_GetEmbeddedFrames
  1431. //--------------------------------------------------------------------
  1432.  
  1433. OrderedCollection* CAProxyPart::UTIL_GetEmbeddedFrames(Environment* ev)
  1434. {
  1435. ODUnused (ev);
  1436.  
  1437.     return (fEmbeddedFrames);
  1438.     
  1439. }
  1440.  
  1441. //--------------------------------------------------------------------
  1442. // CAProxyPart::UTIL_HandleActivateEvent
  1443. //--------------------------------------------------------------------
  1444.  
  1445. ODBoolean CAProxyPart::UTIL_HandleActivateEvent(Environment* ev, ODFrame* frame, ODEventData* event)
  1446. {
  1447.     short                activating = event->modifiers & activeFlag;
  1448.     ODSession*            session = fSelf->GetStorageUnit(ev)->GetSession(ev);
  1449.     ODPlatformWindow    platformWindow;
  1450.     ODWindow*            window;
  1451.  
  1452.  
  1453.     PartInfo*    partInfo = (PartInfo*) frame->GetPartInfo(ev);
  1454.     TempODFrame activeFrame = session->GetArbitrator(ev)->AcquireFocusOwner(ev, gSelectionFocus);
  1455.  
  1456.     if (activating)
  1457.     {    
  1458.  
  1459.         if (partInfo->GetNeedsActivating ())
  1460.         {
  1461.             this->UTIL_ActivateDisplayFrame (ev, frame);
  1462.             partInfo->SetNeedsActivating (kODFalse);
  1463.         }
  1464.         else
  1465.         {
  1466.             //DebugStr ("\pWindow Activating, active frame is not root");
  1467.         }
  1468.         
  1469.     }
  1470.     else
  1471.     {
  1472.     
  1473.  
  1474.         if (partInfo->IsFrameActive())
  1475.         {
  1476.             partInfo->SetNeedsActivating (kODTrue);
  1477.         }
  1478.         else
  1479.         {
  1480.             partInfo->SetNeedsActivating (kODFalse);
  1481.         }
  1482.  
  1483.         InvalMenuBar();
  1484.     }
  1485.         
  1486.     window = frame->AcquireWindow(ev);
  1487.     platformWindow = window->GetPlatformWindow(ev);
  1488.     window->Release(ev);
  1489.         
  1490.     // Call the CA's CAWindowActivateHandler if it exists.
  1491.     if (this->fCAWindowActivateHandler)
  1492.     {
  1493.         CallUniversalProc(fCAWindowActivateHandler, uppCAWindowActivateHandlerInfo,
  1494.                                 platformWindow, activating);
  1495.     }
  1496.  
  1497.     return (kODFalse);
  1498.  
  1499. }
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505. //-------------------------------------------------------------------------
  1506. // CAProxyPart::UTIL_SetDirty
  1507. //-------------------------------------------------------------------------
  1508.  
  1509. void CAProxyPart::UTIL_SetDirty(Environment* ev)
  1510. {
  1511.  
  1512.     // There is no need to repeatedly tell the draft we have changed;
  1513.     // once is sufficient.
  1514.     if (!fReadOnlyStorage )
  1515.     {
  1516.         fDirty = kODTrue;
  1517.         fSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  1518.     }
  1519.  
  1520. }
  1521.  
  1522.